#include <stdio.h>
#include <stdlib.h>
#include <string.h>


//定义一个结构体
//stu相当于 struct student,stud=struct student *
typedef struct student{
	char name[10];
	int age;
	char sex;
}stu,*stud;

//测试指针
void testpoint(){
	int *pointDemo;
	int i = 5;

	//pointDemo存储的是变量i的地址
	pointDemo = &i;
	
	scanf("%d",pointDemo);

	printf("i=%d\n",*pointDemo);
}

//指针的值传递
void change(int *i){
	*i=5;
}

//指针的偏移
void testpianyi(){
	int a[5]={1,2,3,4,5};
	int *p;
	int i;
	p=a;

	for(i=0;i<5;i++){

		//p+1会加一个sizeof(int)；
		printf("%3d",*(p+i));
	}
	printf("\n");
}

//逆置输出数组的值
void revort(){
	int a[5]={1,2,3,4,5};
	int i;
	int *p;
	
	//将指针指向数组的末尾元素
	p=&a[4];
	for(i=0;i<5;i++){
		printf("%d\n",*(p-i));
	}
}

//测试指针数组
void teststring(char *c){
	c[0]='H';

	//*c == 变量c
	*(c+1)='E';
}

//测试malloc函数
void testmalloc(){

	//定义一个指针变量
	char *p;
	int size;
	scanf("%d",&size);
	p=(char*)malloc(size);
	strcpy(p,"hello malloc");
	puts(p);
	free(p);
}

char* getcharmy(){
	char *p;
	int size;
	scanf("%d",&size);
	p=(char*)malloc(size);
	return p;
}



//结构体数组
void structarray(){
	int i;
	int j;
	struct	student array[3];
	struct student	s1;
	//遍历此数组存入三个学生对象
	for(i=0;i<3;i++){
		printf("请输入第%d个学生信息:\n",i+1);
		scanf("%s%d %c",&s1.name,&s1.age,&s1.sex);
		array[i] = s1;
	}


	//遍历输出三个学生对象
	for(j=0;j<3;j++){
		printf("第%d个学生：name=%s,age=%d,sex=%c\n",j+1,array[j].name,array[j].age,array[j].sex);
	}
}


//测试指针
void test001(){
	int i=78;
	int *p;
	p=&i;
	printf("p=%x\n",p);
	printf("&p=%x\n",&p);
	printf("*p=%x\n",*p);
	printf("&i=%x\n",&i);
	printf("i=%x\n",i);
}


//测试p->的使用
void testx(){
	//stu相当于是：struct student
	stu s={"zhangsan",23,'M'};
	//相当于是struct student *
	stud p;
	p=&s;
	printf("name=%s,age=%d,sex=%c\n",(*p).name,(*p).age,(*p).sex);
	printf("name=%s,age=%d,sex=%c\n",p->name,p->age,p->sex);
}

int main(){
	//struct	student s={"zhangsan",13,'M'};
	//printf("name=%s,age=%d,sex=%c\n",s.name,s.age,s.sex);

	//printf("-------请输入新的学生信息---------\n");
	
	//scanf("%s%d %c",&s.name,&s.age,&s.sex);
	//printf("name=%s,age=%d,sex=%c\n",s.name,s.age,s.sex);
	
	testx();

	return 0;
}